package com.changgou.system.util;

import java.security.MessageDigest;
import java.util.UUID;

public class MD5UUIDUtils {


    /**
     * 生成随机字符18位
     *
     */
    static String generateUUID(){

        String uuid = UUID.randomUUID().toString().replaceAll("-","").substring(0,18);

        return uuid;
    }


    /**
     *
     *      MD5
     *
     */
    public static String getMD5(String password){
        try {

            MessageDigest md5 = MessageDigest.getInstance("MD5");

            byte[] bytes = md5.digest(password.getBytes("UTF-8"));

            StringBuilder sb = new StringBuilder();//   使用字符串拼接

            for (byte item:bytes) {
                sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString().toUpperCase();//将得到的md加密字符转成大写

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }


}
